import {Component, OnInit} from '@angular/core';
import {Select, Store} from "@ngxs/store";
import {Shop} from "./store/shop/shop.actions";
import {Observable} from "rxjs";
import {CartModel} from "./store/cart/cart.state";
import {Navigate} from "@ngxs/router-plugin";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
  carts: Shop[] = []
  @Select() cart$: Observable<CartModel>

  constructor(private store: Store,) {
  }

  ngOnInit(): void {
    this.cart$.subscribe(r => {
      this.carts = r.list
    })
  }


  goto(url: string) {
    this.store.dispatch(new Navigate([url], {
      name: 'testName',
      url: url,
    }))
  }
}
